<template>
  <div>

    <a-table bordered :dataSource="dataSource" :columns="columns">
      <span slot="action" slot-scope="data">
        <a-button @click.native="handleDelColumn(data.id)">删除</a-button>
      </span>
    </a-table>
  </div>
</template>

<script>
import * as api from '@/api'
export default {
  data () {
    return {
      dataSource: [],
      columns: [
        {
          title: 'ID',
          dataIndex: 'id'
        },
        {
          title: '作者',
          dataIndex: 'author'
        },
        {
          title: '标题',
          dataIndex: 'post_title'
        },
        {
          title: '播放次数',
          dataIndex: 'showed'
        },
        {
          title: '创建时间',
          dataIndex: 'create_at'
        },
        {
          title: '动作',
          key: 'action11',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  mounted () {
    api.getPosts().then(response => {
      // response
      this.dataSource = response.data
    })
  },
  methods: {
    handleDelColumn (id) {
      api.delPost(id).then(res => {
        if (res.code === 200) {
          this.$message.success(res.message, 1.5, () => {
            this.$router.go(0)
          })
        }
      })
    }
  }
}
</script>

<style>

</style>
